package com.wmwsystems.inc.demo.wsclient;

import org.apache.ws.security.WSConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor;


@Configuration
public class SpringConfiguration {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.wmwsystems.inc.demo.wsdl");

        return marshaller;
    }

    @Bean
    public Wss4jSecurityInterceptor wsClientSecurityInterceptor() {
        Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
        interceptor.setSecurementActions("UsernameToken");
        interceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
        interceptor.setSecurementUsername("1");
        interceptor.setSecurementPassword("RAD#zN2zfXDy+MKhEf6F");

        return interceptor;
    }

    @Bean
    public WsClient wsClient(Jaxb2Marshaller marshaller) {
        WsClient client = new WsClient();
        client.setDefaultUri("https://kuda.integration.realobs.com/Api/Services/FlightsSynchronization.svc");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        client.setInterceptors(new ClientInterceptor[] {
                wsClientSecurityInterceptor()
            });

        return client;
    }

}
